import { Controller, HttpStatus, Post, Body, Get } from '@nestjs/common';
import {
  ApiBody,
  ApiHeader,
  ApiQuery,
  ApiResponse,
  ApiTags,
} from '@nestjs/swagger';
import { QuestionService } from './question.service';
import { Question } from './question.entity';

@Controller('question')
@ApiTags('试题')
export class QuestionController {
  constructor(private readonly questionService: QuestionService) {}

  //post
  @ApiBody({ description: '请求体', type: Question })
  @ApiHeader({
    name: 'token',
    required: true,
    description: '请求的时候 携带token',
  })
  @ApiResponse({ status: HttpStatus.CREATED, description: '请求成功' })
  @ApiResponse({ status: HttpStatus.UNAUTHORIZED, description: '权限不足' })
  @ApiResponse({
    status: HttpStatus.FORBIDDEN,
    description: '此角色无权限操作',
  })
  @Post()
  create(@Body() body) {
    return this.questionService.create(body);
  }

  @ApiQuery({
    name: 'count',
    required: false,
    description: '返回的条数',
  })
  @ApiResponse({ status: HttpStatus.OK, description: '请求成功' })
  @ApiResponse({ status: HttpStatus.UNAUTHORIZED, description: '权限不足' })
  @ApiResponse({
    status: HttpStatus.FORBIDDEN,
    description: '此角色无权限操作',
  })
  @Get()
  getAll() {
    return this.questionService.getAll();
  }
}
